// 提交链接：https://leetcode.cn/problems/time-needed-to-buy-tickets/description/
// lc2073. 买票需要的时间
// 完成日期：2024/9/29
// c++ 队列 数组

class Solution {
public:
    int timeRequiredToBuy(vector<int>& tickets, int k) {
        queue<int> q;
        int time = 0;
        for(int i = 0; i < tickets.size(); ++i)   q.push(i);
        
        while(tickets[k] > 0)
        {
            int index = q.front();
            q.pop();
            tickets[index]--;
            time++;
            if(tickets[index] > 0)
                q.push(index);
        }
        return time; 
    }
};